package logic

import (
	"context"
	"errors"
	"product/model/mysql"

	"product/productrpc/internal/svc"
	"product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopDelLogic {
	return &ShopDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopDelLogic) ShopDel(in *productrpc.ShopDelRequest) (*productrpc.ShopDelResponse, error) {
	// todo: add your logic here and delete this line

	var shop mysql.Shop

	mysql.DB.Debug().Where("id = ?", in.ShopId).Find(&shop)
	if shop.ID == 0 {
		return nil, errors.New("用户不存在，请更换")
	}

	err := mysql.DB.Debug().Where("id = ?", in.ShopId).Delete(&mysql.Shop{}).Error
	if err != nil {
		return nil, err
	}

	return &productrpc.ShopDelResponse{}, nil
}
